<template>
  <div class="account-box">
    <div class="tiao">
      没有账号，去<a href="javascript:;" style="color: #069" @click="$emit('changeTitle')">注册</a>
    </div>
    <nav>账号登录</nav>
    <div class="form">
      <el-form
        :model="ruleForm"
        status-icon
        :rules="rules"
        ref="ruleForm"
        label-width="80px"
        label-position="left"
        class="demo-ruleForm"
      >
        <el-form-item class="item" label="用户名" prop="username">
          <el-input type="text" v-model="ruleForm.username"></el-input>
        </el-form-item>
        <el-form-item class="item" label="密码" prop="password">
          <el-input type="password" v-model="ruleForm.password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button class="button" type="primary" @click="submitForm('ruleForm')">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
// import store from 'vuex'
export default {
  components: {
    // Form,
    // Field
  },
  props: { logOn: Boolean },
  data() {
    return {
      ruleForm: {
        username: '',
        password: ''
      },
      rules: {
        password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { min: 6, max: 16, message: '长度在 6 到 16 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate(async valid => {
        if (valid) {
          // console.log(this.$store);
          this.$store.dispatch('user/login', this.ruleForm)
          // alert('submit!')
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>
<style lang="less" scoped>
// 账号容器
.account-box {
  .button {
    width: 150px;
  }
  .tiao {
    margin: 5px;
  }
  nav {
    height: 50px;
    text-align: center;
    font-size: 25px;
  }
  .toggle {
    padding: 15px 40px;
    text-align: right;
    a {
      color: #666;
      i {
        font-size: 14px;
      }
    }
  }
  .form {
    margin: 20px;
    .item {
      margin-left: 0;
    }
    &-item {
      margin-bottom: 28px;
      .input {
        position: relative;
        height: 36px;
        > i {
          width: 34px;
          height: 34px;
          background: #cfcdcd;
          color: #fff;
          position: absolute;
          left: 1px;
          top: 1px;
          text-align: center;
          line-height: 34px;
          font-size: 18px;
        }
        input {
          padding-left: 44px;
          border: 1px solid #cfcdcd;
          height: 36px;
          line-height: 36px;
          width: 100%;
          &.error {
            border-color: #666;
          }
          &.active,
          &:focus {
            border-color: #666;
          }
        }
        .code {
          position: absolute;
          right: 1px;
          top: 1px;
          text-align: center;
          line-height: 34px;
          font-size: 14px;
          background: #f5f5f5;
          color: #666;
          width: 90px;
          height: 34px;
          cursor: pointer;
        }
      }
      > .error {
        position: absolute;
        font-size: 12px;
        line-height: 28px;
        color: #666;
        i {
          font-size: 14px;
          margin-right: 2px;
        }
      }
    }
    .agree {
      a {
        color: #069;
      }
    }
    .btn {
      display: block;
      width: 100%;
      height: 40px;
      color: #fff;
      text-align: center;
      line-height: 40px;
      background: #666;
      &.disabled {
        background: #cfcdcd;
      }
    }
  }
}
</style>
